package br.com.fiap.cincoMob.TrabalhoFinal;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

public class ItemHistory {
	private Double number1;
	private Double number2;
	private String operator;
	private GregorianCalendar date;
	
	public static SimpleDateFormat formatDate;
	
	static{
		formatDate = new SimpleDateFormat("EEEE dd/MM/yyyy HH:mm:ss");
	}
	
	public ItemHistory(Double number1, Double number2, String operator, GregorianCalendar date) {
		super();
		this.number1 = number1;
		this.number2 = number2;
		this.operator = operator;
		this.date = date;
	}
	
	public ItemHistory(Double number1, Double number2, String operator) {
		this(number1, number2, operator, new GregorianCalendar());
	}
	
	public ItemHistory() {
		this(0.0, 0.0, "", new GregorianCalendar());
	}	

	public Double getNumber1() {
		return number1;
	}

	public void setNumber2(Double number2) {
		this.number2 = number2;
	}

	public Double getNumber2() {
		return number2;
	}

	public void setNumber1(Double number1) {
		this.number1 = number1;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public GregorianCalendar getDate() {
		return date;
	}

	public void setDate(GregorianCalendar date) {
		this.date = date;
	}

	public void setDate() {
		this.date = new GregorianCalendar();
	}
	
	public ItemHistory clone(){
		ItemHistory clone = new ItemHistory(this.number1, this.number2, this.operator, this.date); 
		return clone;
	}

	@Override
	public String toString() {
		return number1 + " " + operator + " " + number2 + " = " + MathUtils.CalculationDouble(number1, number2, operator) 
				+ " - " + formatDate.format(date.getTime()) ;
	}
	
	public void print(int decimalSize){
		String printItem = "Calculation: %." + decimalSize + "f %s %." + decimalSize + "f = %." + decimalSize + "f - %s\n";
		System.out.printf(printItem, number1, operator, number2, MathUtils.CalculationDouble(number1, number2, operator, decimalSize),
							formatDate.format(date.getTime()));
	}
	
	public void print(int decimalSize, PrintWriter out){
		String printItem = "Calculation: %." + decimalSize + "f %s %." + decimalSize + "f = %." + decimalSize + "f - %s\r\n";
		out.printf(printItem, number1, operator, number2, MathUtils.CalculationDouble(number1, number2, operator, decimalSize),
							formatDate.format(date.getTime()));
	}	

}
